package 力扣算法练习.main1.newPart1;

import java.util.LinkedList;

public class day8 {
    //https://www.nowcoder.com/practice/f8538f9ae3f1484fb137789dec6eedb9?tpId=37&tqId=21283&ru=/exam/oj
    private static void solution(int num) {
        int min = Integer.MAX_VALUE;
        int[] res = new int[2];
        // 从2开始穷举
        for(int i = 2; i < num; i++) {
            if(isPrime(i) && isPrime(num - i)) {
                // 保存最接近的两个素数
                if(Math.abs(num - i - i) < min) {
                    res[0] = i;
                    res[1] = num - i;
                    min = Math.abs(num - i - i);
                }
            }
        }
        System.out.println(res[0] + "\n" + res[1]);
    }
    // 判断是否素数
    private static boolean isPrime(int num) {
        for(int i = 2; i <= Math.sqrt(num); i++) {
            if(num % i == 0) {
                return false;
            }
        }
        Integer.toString(5,2);
        return true;
    }


    //https://www.nowcoder.com/questionTerminal/30c1674ad5694b3f8f0bc2de6f005490
    public int binInsert(int n, int m, int j, int i) {
        // write code here
        //获得n和m的二进制
        String ns= Integer.toString(n,2);
        String ms= Integer.toString(m,2);
        char[] chm = ms.toCharArray();
        char[] chn = ns.toCharArray();
        int index= chm.length-1;
        for (int k = chn.length-j-1; k >=chn.length-i-1&&index>=0; k--) {
            chn[k]=chm[index--];
        }
        System.out.println();
        int result=0,two=1;
        for (int k = chn.length-1; k >=0 ; k--) {
            result+=(chn[k]-'0')*two;
            two*=2;
        }
        return result;
    }

    public static void main(String[] args) {
        day8 iu=new day8();
        System.out.println(iu.binInsert(4355, 4, 2, 7));
    }
}
